// license-header java merge-point
/**
 * This is only generated once! It will never be overwritten.
 * You can (and have to!) safely modify it by hand.
 */
package edu.uwlax.cs.oayonlinestore.entities;

import java.util.Date;

import edu.uwlax.cs.oayonlinestore.vo.SnapshotVO;

/**
 * @see edu.uwlax.cs.oayonlinestore.entities.Snapshot
 */
public class SnapshotDaoImpl extends SnapshotDaoBase {
	/**
	 * Retrieves the entity object that is associated with the specified value
	 * object from the object store. If no such entity object exists in the
	 * object store, a new, blank entity is created
	 */
	private Snapshot loadSnapshotFromSnapshotVO(SnapshotVO snapshotVO) {

		Snapshot snapshot = this.load(snapshotVO.getId());
		if (snapshot == null) {
			snapshot = Snapshot.Factory.newInstance();
		}
		return snapshot;

	}

	public Snapshot snapshotVOToEntity(SnapshotVO snapshotVO) {
		Snapshot entity = this.loadSnapshotFromSnapshotVO(snapshotVO);
		this.snapshotVOToEntity(snapshotVO, entity, true);
		return entity;
	}

	public void toSnapshotVO(Snapshot source, SnapshotVO target) {
		super.toSnapshotVO(source, target);
		if (source.getDate() != null)
			target.setDate(new Date(source.getDate().getTime()));
	}

}